<?php

/**
 * CCoreLoggerInline
 *
 * @author Usenko Timur <usenko.timur@gmail.com>
 * @package logger
 */

CCore::Using('logger.abstract');

/**
 * @package logger
 */
class CCoreLoggerInline extends ACoreLogger
{
	#<editor-fold defaultstate="collapsed" desc="private">
	/**
	 * @var string
	 */
	private $_sNewLine;

	/**
	 * @var bool
	 */
	private $_bHtmlEncodeSpecialChars;
	#</editor-fold>

	/**
	 * @param string $sNewLine = "\n"
	 * @param bool $bHtmlEncodeSpecialChars = false
	 * @return CCoreLoggerInline
	 */
	public function __construct($sNewLine = "\n", $bHtmlEncodeSpecialChars = false)
	{
		CCore::CheckTypes(array('$sNewLine', '$bHtmlEncodeSpecialChars'));
		
		$this->_sNewLine = $sNewLine;
		$this->_bHtmlEncodeSpecialChars = $bHtmlEncodeSpecialChars;
	}
	
	/**
	 * @param string $sErrorDesc
	 * @return bool
	 */
	protected function writeImplementation($sErrorDesc)
	{
		CCore::CheckTypes(array('$sErrorDesc'));

		echo ($this->_bHtmlEncodeSpecialChars)
			? htmlspecialchars($sErrorDesc).$this->_sNewLine : $sErrorDesc.$this->_sNewLine;
		
		return true;
	}

	/**
	 * @param string $sTimePrefix
	 * @param string $sErrorDesc
	 * @return string
	 */
	protected function logLineImplementation($sTimePrefix, $sErrorDesc)
	{
		CCore::CheckTypes(array('$sTimePrefix', '$sErrorDesc'));
		
		return '['.$sTimePrefix.'] '.$sErrorDesc;
	}

	/**
	 * @return bool
	 */
	protected function clearImplementation()
	{
		return true;
	}
}
